// import axios from 'axios'
import axios from '@/api/baseHttp'
export function postExport (params, url) {
  return axios.post(`${url}`, params)
}
export function getExport (params, url) {
  return axios.get(`${url}`, params)
}
export function getBlobExport (params, url) {
  return axios({
    url: `${url}`,
    params,
    responseType: 'blob'
  })
}

export function getOrpost (params, url, method) {
  return method === 'get' ? getExport(params, url) : postExport(params, url)
}

export function downloadFile (blob, fileName) {
  if (!blob) {
    return
  }
  let _blob = new Blob([blob], { type: 'application/vnd.ms-excel' })
  let url = window.URL.createObjectURL(_blob)
  let link = document.createElement('a')
  link.style.display = 'none'
  link.href = url
  link.setAttribute('download', fileName || '下载.xlsx')
  document.body.appendChild(link)
  link.click()

  setTimeout(() => {
    document.body.removeChild(link)
  }, 20000)
}
